/**
 * Created by isoft-work 5 on 1/17/2015.
 */
$(document).ready(function(){
   bindEventReportUser();
});

function bindEventReportUser() {
   ISS.EVENT.bindEvent('#result_report', 'click', function () {
      getUserReport();
   });
}

function getUserReport() {
   var _option = ISS.DOM.getVal("#option_report");
   var _date = ISS.DOM.getVal("#input_name_time");
   if(_option && _date) {
      if(_option == CONSTANT.ReportUser.Month) {
         getBuyMonthReport(_date);
      }
   }
   else {
      alert('Chưa chọn thông kê hoặc thời gian');
   }
}

function getBuyMonthReport(date) {
   ISS.BACKEND.request({
      url: '../../service/admin/report/getRevenueBuyOfUser/' + date,
      headers: {
         'Accept': 'application/json',
         'Content-Type': 'application/json'
      },
      type: 'GET',
      dataType: 'json',
      success: function (data) {
         var responseContent = data.responseObject;
         mapBuyMonthToView(responseContent);
      }
   });
}

function mapBuyMonthToView(buyMonth) {
   if(buyMonth.length > 0) {
      var _html = '';
      for(var i = 0; i < buyMonth.length; i++) {
         _html += ISS.TEMPLATE.handleBar.renderByString(TEMPLATE.UserReport.monthList, buyMonth[i]);
      }
      ISS.DOM.html('#header_report_user', TEMPLATE.UserReport.monthHeader);
      ISS.DOM.html('#list_report_user', _html);
      ISS.DOM.pagingAdmin('#result_report_user');
      ISS.DOM.show('#paging');
   }
}
